package com.mycompany.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.mycompany.model.User;
import com.mycompany.repositories.UserRepository;

@Component
@Repository
public class UserDao {

	
	@Autowired
	UserRepository userRepository;
	
	@PersistenceContext(unitName="myUnit")
	EntityManager entityManager;
	
	public void saveUser(User user){
		userRepository.save(user);
		
	}
	
	public List<User> selectAll(){
		return userRepository.findAll();
		
	}
	
	public void testEntityManager(){
		System.out.println();
		
	}
	
	public List<User> pageableUsers(int startIndex, int endIndex){
		 
		Pageable pageable = new PageRequest(startIndex, endIndex);
		return userRepository.findAll(pageable).getContent(); 
	
	}
	
	public void deleteUser(User user){
		userRepository.delete(user);

	}
	
	
}
